package com.huobao.yunying.activitys;

import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class Act_Message_TypeList extends HuobaoBaseActivity implements OnClickListener {

	// 退换货
	@ViewInject(R.id.llyt_1)
	private View view_tuihuanhuo;
	// 私信
	@ViewInject(R.id.llyt_2)
	private View view_sixin;
	// 公告
	@ViewInject(R.id.llyt_3)
	private View view_gonggao;

	@ViewInject(R.id.tv_1)
	private TextView tv_1;

	@ViewInject(R.id.tv_2)
	private TextView tv_2;
	@ViewInject(R.id.tv_3)
	private TextView tv_3;

	@Override
	protected int getContentView() {
		return R.layout.layout_message_type_list;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "消息记录";
	}

	private void getMessage() {
		Map<String, String> map = HttpUtil.getParams("app", "message");
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				// 退货信息数
				int refundnum = jsonObject.getIntValue("refundnum");
				// 私信数量
				int msgnum = jsonObject.getIntValue("msgnum");
				// 公告数量
				int noticenum = jsonObject.getIntValue("noticenum");
				if (refundnum == 0)
					tv_1.setVisibility(View.GONE);
				else
					tv_1.setVisibility(View.VISIBLE);
				if (msgnum == 0)
					tv_2.setVisibility(View.GONE);
				else
					tv_2.setVisibility(View.VISIBLE);
				if (noticenum == 0)
					tv_3.setVisibility(View.GONE);
				else
					tv_3.setVisibility(View.VISIBLE);
				tv_1.setText(refundnum + "");
				tv_2.setText(msgnum + "");
				tv_3.setText(noticenum + "");
			}

			@Override
			public void onHttpError(String error) {
			}
		});
	}

	@Override
	protected void init() {
		view_tuihuanhuo.setOnClickListener(this);
		view_sixin.setOnClickListener(this);
		view_gonggao.setOnClickListener(this);
		getMessage();
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent();
		switch (v.getId()) {
		case R.id.llyt_1:
			startActivity(new Intent(context, Act_DingDanGuanli.class).putExtra("pos", 3));
			break;
		case R.id.llyt_2:
			// intent.setClass(context, Act_Sixin.class);
			// startActivity(intent);
			break;
		case R.id.llyt_3:
			 intent.setClass(context, Act_Gonggao.class);
			 startActivity(intent);
			break;
		}
	}

}
